module decode_vn(
//时钟复位
i_clk,
i_rst_n,
//解码使能
i_decode_en,
//控制信号、迭代计数器
i_decode_cnt,
i_err_cnt,
//8个输入数据
i_di,
//8列后验信息（上一轮）
i_lr_last,
//8列c2v
i_c2v_0,
i_c2v_1,
i_c2v_2,
i_c2v_3,
i_c2v_4,
i_c2v_5,
i_c2v_6,
i_c2v_7,
//8列校验v2c
o_v2c_check_0,
o_v2c_check_1,
o_v2c_check_2,
o_v2c_check_3,
o_v2c_check_4,
o_v2c_check_5,
o_v2c_check_6,
o_v2c_check_7,
//8列迭代v2c
o_v2c_ite_0,
o_v2c_ite_1,
o_v2c_ite_2,
o_v2c_ite_3,
o_v2c_ite_4,
o_v2c_ite_5,
o_v2c_ite_6,
o_v2c_ite_7,
//8列后验信息（下一轮）
o_lr_next,
//输出地址数据
o_decode_addr,
o_decode_data
);

//时钟复位
input              i_clk;
input              i_rst_n;
//解码使能
input              i_decode_en;
//控制信号、迭代计数器
input      [8:0]   i_decode_cnt;
input      [5:0]   i_err_cnt;
//8个输入数据
input      [31:0]  i_di;
//8列后验信息（上一轮）
input      [511:0] i_lr_last;
//8列c2v
input      [15:0]  i_c2v_0;
input      [15:0]  i_c2v_1;
input      [15:0]  i_c2v_2;
input      [15:0]  i_c2v_3;
input      [15:0]  i_c2v_4;
input      [15:0]  i_c2v_5;
input      [15:0]  i_c2v_6;
input      [15:0]  i_c2v_7;
//8列校验v2c
output reg [15:0]  o_v2c_check_0;
output reg [15:0]  o_v2c_check_1;
output reg [15:0]  o_v2c_check_2;
output reg [15:0]  o_v2c_check_3;
output reg [15:0]  o_v2c_check_4;
output reg [15:0]  o_v2c_check_5;
output reg [15:0]  o_v2c_check_6;
output reg [15:0]  o_v2c_check_7;
//8列迭代v2c
output reg [15:0]  o_v2c_ite_0;
output reg [15:0]  o_v2c_ite_1;
output reg [15:0]  o_v2c_ite_2;
output reg [15:0]  o_v2c_ite_3;
output reg [15:0]  o_v2c_ite_4;
output reg [15:0]  o_v2c_ite_5;
output reg [15:0]  o_v2c_ite_6;
output reg [15:0]  o_v2c_ite_7;
//8列后验信息（下一轮）
output     [511:0] o_lr_next;
//输出地址数据
output     [8:0]   o_decode_addr;
output     [31:0]  o_decode_data;

wire [0:63] lr_last_0;
wire [0:63] lr_last_1;
wire [0:63] lr_last_2;
wire [0:63] lr_last_3;
wire [0:63] lr_last_4;
wire [0:63] lr_last_5;
wire [0:63] lr_last_6;
wire [0:63] lr_last_7;

reg [0:63] lr_next_0;
reg [0:63] lr_next_1;
reg [0:63] lr_next_2;
reg [0:63] lr_next_3;
reg [0:63] lr_next_4;
reg [0:63] lr_next_5;
reg [0:63] lr_next_6;
reg [0:63] lr_next_7;

assign lr_last_0 = i_lr_last[511:448];
assign lr_last_1 = i_lr_last[447:384];
assign lr_last_2 = i_lr_last[383:320];
assign lr_last_3 = i_lr_last[319:256];
assign lr_last_4 = i_lr_last[255:192];
assign lr_last_5 = i_lr_last[191:128];
assign lr_last_6 = i_lr_last[127:64] ;
assign lr_last_7 = i_lr_last[63:0]   ;

assign o_lr_next = {lr_next_0,lr_next_1,lr_next_2,lr_next_3,lr_next_4,lr_next_5,lr_next_6,lr_next_7};

assign o_decode_addr = i_decode_cnt - 9'd2;
assign o_decode_data = {o_v2c_check_0[15:12],o_v2c_check_1[15:12],o_v2c_check_2[15:12],o_v2c_check_3[15:12],
                        o_v2c_check_4[15:12],o_v2c_check_5[15:12],o_v2c_check_6[15:12],o_v2c_check_7[15:12]};

//c2v值转llr
function [0:63] c2v2l;
input [3:0] c2v;
    case(c2v)
        4'b0000 : c2v2l = 64'h0_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1;
        4'b0001 : c2v2l = 64'h1_0_1_1_1_1_1_1_1_1_1_1_1_1_1_1;
        4'b0010 : c2v2l = 64'h1_1_0_1_1_1_1_1_1_1_1_1_1_1_1_1;
        4'b0011 : c2v2l = 64'h1_1_1_0_1_1_1_1_1_1_1_1_1_1_1_1;
        4'b0100 : c2v2l = 64'h1_1_1_1_0_1_1_1_1_1_1_1_1_1_1_1;
        4'b0101 : c2v2l = 64'h1_1_1_1_1_0_1_1_1_1_1_1_1_1_1_1;
        4'b0110 : c2v2l = 64'h1_1_1_1_1_1_0_1_1_1_1_1_1_1_1_1;
        4'b0111 : c2v2l = 64'h1_1_1_1_1_1_1_0_1_1_1_1_1_1_1_1;
        4'b1000 : c2v2l = 64'h1_1_1_1_1_1_1_1_0_1_1_1_1_1_1_1;
        4'b1001 : c2v2l = 64'h1_1_1_1_1_1_1_1_1_0_1_1_1_1_1_1;
        4'b1010 : c2v2l = 64'h1_1_1_1_1_1_1_1_1_1_0_1_1_1_1_1;
        4'b1011 : c2v2l = 64'h1_1_1_1_1_1_1_1_1_1_1_0_1_1_1_1;
        4'b1100 : c2v2l = 64'h1_1_1_1_1_1_1_1_1_1_1_1_0_1_1_1;
        4'b1101 : c2v2l = 64'h1_1_1_1_1_1_1_1_1_1_1_1_1_0_1_1;
        4'b1110 : c2v2l = 64'h1_1_1_1_1_1_1_1_1_1_1_1_1_1_0_1;
        4'b1111 : c2v2l = 64'h1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_0;
    endcase
endfunction

//输入数据转llr
function [0:63] d2l;
input [3:0] di;
    case(di)
        4'b0000 : d2l = 64'h0_1_1_2_1_2_2_3_1_2_2_3_2_3_3_4;
        4'b0001 : d2l = 64'h1_0_2_1_2_1_3_2_2_1_3_2_3_2_4_3;
        4'b0010 : d2l = 64'h1_2_0_1_2_3_1_2_2_3_1_2_3_4_2_3;
        4'b0011 : d2l = 64'h2_1_1_0_3_2_2_1_3_2_2_1_4_3_3_2;
        4'b0100 : d2l = 64'h1_2_2_3_0_1_1_2_2_3_3_4_1_2_2_3;
        4'b0101 : d2l = 64'h2_1_3_2_1_0_2_1_3_2_4_3_2_1_3_2;
        4'b0110 : d2l = 64'h2_3_1_2_1_2_0_1_3_4_2_3_2_3_1_2;
        4'b0111 : d2l = 64'h3_2_2_1_2_1_1_0_4_3_3_2_3_2_2_1;
        4'b1000 : d2l = 64'h1_2_2_3_2_3_3_4_0_1_1_2_1_2_2_3;
        4'b1001 : d2l = 64'h2_1_3_2_3_2_4_3_1_0_2_1_2_1_3_2;
        4'b1010 : d2l = 64'h2_3_1_2_3_4_2_3_1_2_0_1_2_3_1_2;
        4'b1011 : d2l = 64'h3_2_2_1_4_3_3_2_2_1_1_0_3_2_2_1;
        4'b1100 : d2l = 64'h2_3_3_4_1_2_2_3_1_2_2_3_0_1_1_2;
        4'b1101 : d2l = 64'h3_2_4_3_2_1_3_2_2_1_3_2_1_0_2_1;
        4'b1110 : d2l = 64'h3_4_2_3_2_3_1_2_2_3_1_2_1_2_0_1;
        4'b1111 : d2l = 64'h4_3_3_2_3_2_2_1_3_2_2_1_2_1_1_0;
    endcase
endfunction

//llr转v2c
//单数顺查
function[3:0] cam1;
input [0:63] lr;
    begin
    if(lr[0:3] == 4'b0)
        cam1 = 4'b0000;
    else if(lr[4:7] == 4'b0)
        cam1 = 4'b0001;
    else if(lr[8:11] == 4'b0) 
        cam1 = 4'b0010;
    else if(lr[12:15] == 4'b0) 
        cam1 = 4'b0011; 
    else if(lr[16:19] == 4'b0) 
        cam1 = 4'b0100;
    else if(lr[20:23] == 4'b0) 
        cam1 = 4'b0101;
    else if(lr[24:27] == 4'b0) 
        cam1 = 4'b0110; 
    else if(lr[28:31] == 4'b0) 
        cam1 = 4'b0111; 
    else if(lr[32:35] == 4'b0)
        cam1 = 4'b1000;
    else if(lr[36:39] == 4'b0)
        cam1 = 4'b1001;
    else if(lr[40:43] == 4'b0) 
        cam1 = 4'b1010;
    else if(lr[44:47] == 4'b0) 
        cam1 = 4'b1011; 
    else if(lr[48:51] == 4'b0) 
        cam1 = 4'b1100;
    else if(lr[52:55] == 4'b0) 
        cam1 = 4'b1101;
    else if(lr[56:59] == 4'b0) 
        cam1 = 4'b1110;
    else
        cam1 = 4'b1111;  
    end  
endfunction
//双数反查
function[3:0] cam2;
input [0:63] lr;
    begin
    if(lr[60:63] == 4'b0)
        cam2 = 4'b1111;
    else if(lr[56:59] == 4'b0)
        cam2 = 4'b1110;
    else if(lr[52:55] == 4'b0) 
        cam2 = 4'b1101;
    else if(lr[48:51] == 4'b0) 
        cam2 = 4'b1100; 
    else if(lr[44:47] == 4'b0) 
        cam2 = 4'b1011;
    else if(lr[40:43] == 4'b0) 
        cam2 = 4'b1010;
    else if(lr[36:39] == 4'b0) 
        cam2 = 4'b1001; 
    else if(lr[32:35] == 4'b0) 
        cam2 = 4'b1000; 
    else if(lr[28:31] == 4'b0)
        cam2 = 4'b0111;
    else if(lr[24:27] == 4'b0)
        cam2 = 4'b0110;
    else if(lr[20:23] == 4'b0) 
        cam2 = 4'b0101;
    else if(lr[16:19] == 4'b0) 
        cam2 = 4'b0100; 
    else if(lr[12:15] == 4'b0) 
        cam2 = 4'b0011;
    else if(lr[8:11] == 4'b0) 
        cam2 = 4'b0010;
    else if(lr[4:7] == 4'b0) 
        cam2 = 4'b0001;
    else
        cam2 = 4'b0000;  
    end  
endfunction

//取两个中最小值
function [3:0] get_min;
input [3:0] a,b;
    if(a <= b)
        get_min = a;
    else
        get_min = b;
endfunction

//取所有最小值
function[3:0] get_min16;
input [3:0] a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15;
    reg[3:0] t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14;
    begin
        t1  = get_min(a0,a1);//
        t2  = get_min(a2,a3);//
        t3  = get_min(a4,a5);//
        t4  = get_min(a6,a7);//
        t5  = get_min(a8,a9);//
        t6  = get_min(a10,a11);//
        t7  = get_min(a12,a13);//
        t8  = get_min(a14,a15);//
        t9  = get_min(t1,t2);//
        t10 = get_min(t3,t4);//
        t11 = get_min(t5,t6);//
        t12 = get_min(t7,t8);//
        t13 = get_min(t9,t10);
        t14 = get_min(t11,t12);
        get_min16 = get_min(t13,t14);
    end
endfunction

//压缩
function [3:0] cd;
input [3:0] f;
    begin
    if(f == 4'b0) 
    cd = 4'b0;
    else if(f < 4'd3) 
    cd = 4'd1;
    else if(f < 4'd6) 
    cd = 4'd2;
    else if(f < 4'd11) 
    cd = 4'd3;
    else 
    cd = 4'd4;
    end
endfunction

//相加减最小压缩
function [0:63] plus_sub_min;
input [0:63] lr;
input [0:63] c2v0lr;
input [0:63] c2v1lr;
input [0:63] c2v2lr;
input [0:63] c2v3lr;
input [0:63] dilr;
    reg [0:63] llr_plus;
    reg [3:0]  llr_min;
    reg [0:63] llr_sub;
    begin
        //相加
        llr_plus[0:3]   = lr[0:3]   + c2v0lr[0:3]   + c2v1lr[0:3]   + c2v2lr[0:3]   + c2v3lr[0:3]   + dilr[0:3]   ;
        llr_plus[4:7]   = lr[4:7]   + c2v0lr[4:7]   + c2v1lr[4:7]   + c2v2lr[4:7]   + c2v3lr[4:7]   + dilr[4:7]   ;
        llr_plus[8:11]  = lr[8:11]  + c2v0lr[8:11]  + c2v1lr[8:11]  + c2v2lr[8:11]  + c2v3lr[8:11]  + dilr[8:11]  ;
        llr_plus[12:15] = lr[12:15] + c2v0lr[12:15] + c2v1lr[12:15] + c2v2lr[12:15] + c2v3lr[12:15] + dilr[12:15] ;
        llr_plus[16:19] = lr[16:19] + c2v0lr[16:19] + c2v1lr[16:19] + c2v2lr[16:19] + c2v3lr[16:19] + dilr[16:19] ;
        llr_plus[20:23] = lr[20:23] + c2v0lr[20:23] + c2v1lr[20:23] + c2v2lr[20:23] + c2v3lr[20:23] + dilr[20:23] ;
        llr_plus[24:27] = lr[24:27] + c2v0lr[24:27] + c2v1lr[24:27] + c2v2lr[24:27] + c2v3lr[24:27] + dilr[24:27] ;
        llr_plus[28:31] = lr[28:31] + c2v0lr[28:31] + c2v1lr[28:31] + c2v2lr[28:31] + c2v3lr[28:31] + dilr[28:31] ;
        llr_plus[32:35] = lr[32:35] + c2v0lr[32:35] + c2v1lr[32:35] + c2v2lr[32:35] + c2v3lr[32:35] + dilr[32:35] ;
        llr_plus[36:39] = lr[36:39] + c2v0lr[36:39] + c2v1lr[36:39] + c2v2lr[36:39] + c2v3lr[36:39] + dilr[36:39] ;
        llr_plus[40:43] = lr[40:43] + c2v0lr[40:43] + c2v1lr[40:43] + c2v2lr[40:43] + c2v3lr[40:43] + dilr[40:43] ;
        llr_plus[44:47] = lr[44:47] + c2v0lr[44:47] + c2v1lr[44:47] + c2v2lr[44:47] + c2v3lr[44:47] + dilr[44:47] ;
        llr_plus[48:51] = lr[48:51] + c2v0lr[48:51] + c2v1lr[48:51] + c2v2lr[48:51] + c2v3lr[48:51] + dilr[48:51] ;
        llr_plus[52:55] = lr[52:55] + c2v0lr[52:55] + c2v1lr[52:55] + c2v2lr[52:55] + c2v3lr[52:55] + dilr[52:55] ;
        llr_plus[56:59] = lr[56:59] + c2v0lr[56:59] + c2v1lr[56:59] + c2v2lr[56:59] + c2v3lr[56:59] + dilr[56:59] ;
        llr_plus[60:63] = lr[60:63] + c2v0lr[60:63] + c2v1lr[60:63] + c2v2lr[60:63] + c2v3lr[60:63] + dilr[60:63] ;
        //找最小值
        llr_min = get_min16(llr_plus[0:3]  ,llr_plus[4:7]  ,llr_plus[8:11] ,llr_plus[12:15],llr_plus[16:19],llr_plus[20:23],llr_plus[24:27],llr_plus[28:31],
                            llr_plus[32:35],llr_plus[36:39],llr_plus[40:43],llr_plus[44:47],llr_plus[48:51],llr_plus[52:55],llr_plus[56:59],llr_plus[60:63]);
        //减最小值
        llr_sub[0:3]   = llr_plus[0:3]   - llr_min;
        llr_sub[4:7]   = llr_plus[4:7]   - llr_min;
        llr_sub[8:11]  = llr_plus[8:11]  - llr_min;
        llr_sub[12:15] = llr_plus[12:15] - llr_min;
        llr_sub[16:19] = llr_plus[16:19] - llr_min;
        llr_sub[20:23] = llr_plus[20:23] - llr_min;
        llr_sub[24:27] = llr_plus[24:27] - llr_min;
        llr_sub[28:31] = llr_plus[28:31] - llr_min;
        llr_sub[32:35] = llr_plus[32:35] - llr_min;
        llr_sub[36:39] = llr_plus[36:39] - llr_min;
        llr_sub[40:43] = llr_plus[40:43] - llr_min;
        llr_sub[44:47] = llr_plus[44:47] - llr_min;
        llr_sub[48:51] = llr_plus[48:51] - llr_min;
        llr_sub[52:55] = llr_plus[52:55] - llr_min;
        llr_sub[56:59] = llr_plus[56:59] - llr_min;
        llr_sub[60:63] = llr_plus[60:63] - llr_min;
        //压缩
        plus_sub_min = {cd(llr_sub[0:3]  ),cd(llr_sub[4:7]  ),cd(llr_sub[8:11] ),cd(llr_sub[12:15]),cd(llr_sub[16:19]),cd(llr_sub[20:23]),cd(llr_sub[24:27]),cd(llr_sub[28:31]),
                        cd(llr_sub[32:35]),cd(llr_sub[36:39]),cd(llr_sub[40:43]),cd(llr_sub[44:47]),cd(llr_sub[48:51]),cd(llr_sub[52:55]),cd(llr_sub[56:59]),cd(llr_sub[60:63])};
    end
endfunction

always @(posedge i_clk or negedge i_rst_n)
if(!i_rst_n)begin
    o_v2c_check_0 <= 16'b0;
    o_v2c_check_1 <= 16'b0;
    o_v2c_check_2 <= 16'b0;
    o_v2c_check_3 <= 16'b0;
    o_v2c_check_4 <= 16'b0;
    o_v2c_check_5 <= 16'b0;
    o_v2c_check_6 <= 16'b0;
    o_v2c_check_7 <= 16'b0;

    o_v2c_ite_0   <= 16'b0;
    o_v2c_ite_1   <= 16'b0;
    o_v2c_ite_2   <= 16'b0;
    o_v2c_ite_3   <= 16'b0;
    o_v2c_ite_4   <= 16'b0;
    o_v2c_ite_5   <= 16'b0;
    o_v2c_ite_6   <= 16'b0;
    o_v2c_ite_7   <= 16'b0;

    lr_next_0     <= 64'b0;
    lr_next_1     <= 64'b0;
    lr_next_2     <= 64'b0;
    lr_next_3     <= 64'b0;
    lr_next_4     <= 64'b0;
    lr_next_5     <= 64'b0;
    lr_next_6     <= 64'b0;
    lr_next_7     <= 64'b0;
end
else if(i_decode_en && i_decode_cnt >= 9'd1 && i_decode_cnt <= 9'd288)begin//变量节点计算区间
    if(i_err_cnt == 6'b0)begin//第一次不纠错直接输出
        o_v2c_check_0 <= { i_di[31:28], i_di[31:28], i_di[31:28], i_di[31:28] };
        o_v2c_check_1 <= { i_di[27:24], i_di[27:24], i_di[27:24], i_di[27:24] };
        o_v2c_check_2 <= { i_di[23:20], i_di[23:20], i_di[23:20], i_di[23:20] };
        o_v2c_check_3 <= { i_di[19:16], i_di[19:16], i_di[19:16], i_di[19:16] };
        o_v2c_check_4 <= { i_di[15:12], i_di[15:12], i_di[15:12], i_di[15:12] };
        o_v2c_check_5 <= { i_di[11:8] , i_di[11:8] , i_di[11:8] , i_di[11:8]  };
        o_v2c_check_6 <= { i_di[7:4]  , i_di[7:4]  , i_di[7:4]  , i_di[7:4]   };
        o_v2c_check_7 <= { i_di[3:0]  , i_di[3:0]  , i_di[3:0]  , i_di[3:0]   };

        o_v2c_ite_0 <= { i_di[31:28], i_di[31:28], i_di[31:28], i_di[31:28] };
        o_v2c_ite_1 <= { i_di[27:24], i_di[27:24], i_di[27:24], i_di[27:24] };
        o_v2c_ite_2 <= { i_di[23:20], i_di[23:20], i_di[23:20], i_di[23:20] };
        o_v2c_ite_3 <= { i_di[19:16], i_di[19:16], i_di[19:16], i_di[19:16] };
        o_v2c_ite_4 <= { i_di[15:12], i_di[15:12], i_di[15:12], i_di[15:12] };
        o_v2c_ite_5 <= { i_di[11:8] , i_di[11:8] , i_di[11:8] , i_di[11:8]  };
        o_v2c_ite_6 <= { i_di[7:4]  , i_di[7:4]  , i_di[7:4]  , i_di[7:4]   };
        o_v2c_ite_7 <= { i_di[3:0]  , i_di[3:0]  , i_di[3:0]  , i_di[3:0]   };

        lr_next_0     <= d2l(i_di[31:28]);
        lr_next_1     <= d2l(i_di[27:24]);
        lr_next_2     <= d2l(i_di[23:20]);
        lr_next_3     <= d2l(i_di[19:16]);
        lr_next_4     <= d2l(i_di[15:12]);
        lr_next_5     <= d2l(i_di[11:8] );
        lr_next_6     <= d2l(i_di[7:4]  );
        lr_next_7     <= d2l(i_di[3:0]  );
    end
    else if(i_err_cnt[0] == 1'b1) begin
        o_v2c_check_0 <= { cam1( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), 64'b0 ) ),
                           cam1( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), 64'b0 ) ) };
        o_v2c_check_1 <= { cam1( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), 64'b0 ) ),
                           cam1( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), 64'b0 ) ) };
        o_v2c_check_2 <= { cam1( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), 64'b0 ) ),
                           cam1( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), 64'b0 ) ) };
        o_v2c_check_3 <= { cam1( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), 64'b0 ) ),
                           cam1( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), 64'b0 ) ) };
        o_v2c_check_4 <= { cam1( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), 64'b0 ) ),
                           cam1( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), 64'b0 ) ) };
        o_v2c_check_5 <= { cam1( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), 64'b0 ) ),
                           cam1( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), 64'b0 ) ) };
        o_v2c_check_6 <= { cam1( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), 64'b0 ) ),
                           cam1( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), 64'b0 ) ) };
        o_v2c_check_7 <= { cam1( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), 64'b0 ) ),
                           cam1( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), 64'b0 ) ), 
                           cam1( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), 64'b0 ) ) };

        o_v2c_ite_0   <= { cam1( plus_sub_min( lr_last_0,                 64'b0, c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), d2l(i_di[31:28]) ) ),
                           cam1( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]),                64'b0, c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), d2l(i_di[31:28]) ) ), 
                           cam1( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]),               64'b0, c2v2l(i_c2v_0[3:0]), d2l(i_di[31:28]) ) ), 
                           cam1( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]),               64'b0, d2l(i_di[31:28]) ) ) };
        o_v2c_ite_1   <= { cam1( plus_sub_min( lr_last_1,                 64'b0, c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), d2l(i_di[27:24]) ) ),
                           cam1( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]),                64'b0, c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), d2l(i_di[27:24]) ) ), 
                           cam1( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]),               64'b0, c2v2l(i_c2v_1[3:0]), d2l(i_di[27:24]) ) ), 
                           cam1( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]),               64'b0, d2l(i_di[27:24]) ) ) };
        o_v2c_ite_2   <= { cam1( plus_sub_min( lr_last_2,                 64'b0, c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), d2l(i_di[23:20]) ) ),
                           cam1( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]),                64'b0, c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), d2l(i_di[23:20]) ) ), 
                           cam1( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]),               64'b0, c2v2l(i_c2v_2[3:0]), d2l(i_di[23:20]) ) ), 
                           cam1( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]),               64'b0, d2l(i_di[23:20]) ) ) };
        o_v2c_ite_3   <= { cam1( plus_sub_min( lr_last_3,                 64'b0, c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), d2l(i_di[19:16]) ) ),
                           cam1( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]),                64'b0, c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), d2l(i_di[19:16]) ) ), 
                           cam1( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]),               64'b0, c2v2l(i_c2v_3[3:0]), d2l(i_di[19:16]) ) ), 
                           cam1( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]),               64'b0, d2l(i_di[19:16]) ) ) };
        o_v2c_ite_4   <= { cam1( plus_sub_min( lr_last_4,                 64'b0, c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), d2l(i_di[15:12]) ) ),
                           cam1( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]),                64'b0, c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), d2l(i_di[15:12]) ) ), 
                           cam1( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]),               64'b0, c2v2l(i_c2v_4[3:0]), d2l(i_di[15:12]) ) ), 
                           cam1( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]),               64'b0, d2l(i_di[15:12]) ) ) };
        o_v2c_ite_5   <= { cam1( plus_sub_min( lr_last_5,                 64'b0, c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), d2l(i_di[11:8] ) ) ),
                           cam1( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]),                64'b0, c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), d2l(i_di[11:8] ) ) ), 
                           cam1( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]),               64'b0, c2v2l(i_c2v_5[3:0]), d2l(i_di[11:8] ) ) ), 
                           cam1( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]),               64'b0, d2l(i_di[11:8] ) ) ) };
        o_v2c_ite_6   <= { cam1( plus_sub_min( lr_last_6,                 64'b0, c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), d2l(i_di[7:4]  ) ) ),
                           cam1( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]),                64'b0, c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), d2l(i_di[7:4]  ) ) ), 
                           cam1( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]),               64'b0, c2v2l(i_c2v_6[3:0]), d2l(i_di[7:4]  ) ) ), 
                           cam1( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]),               64'b0, d2l(i_di[7:4]  ) ) ) };
        o_v2c_ite_7   <= { cam1( plus_sub_min( lr_last_7,                 64'b0, c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), d2l(i_di[3:0]  ) ) ),
                           cam1( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]),                64'b0, c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), d2l(i_di[3:0]  ) ) ), 
                           cam1( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]),               64'b0, c2v2l(i_c2v_7[3:0]), d2l(i_di[3:0]  ) ) ), 
                           cam1( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]),               64'b0, d2l(i_di[3:0]  ) ) ) };

        lr_next_0     <= plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), 64'b0 );
        lr_next_1     <= plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), 64'b0 );
        lr_next_2     <= plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), 64'b0 );
        lr_next_3     <= plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), 64'b0 );
        lr_next_4     <= plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), 64'b0 );
        lr_next_5     <= plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), 64'b0 );
        lr_next_6     <= plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), 64'b0 );
        lr_next_7     <= plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), 64'b0 );
    end
    else if(i_err_cnt[0] == 1'b0) begin
        o_v2c_check_0 <= { cam2( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), 64'b0 ) ),
                           cam2( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), 64'b0 ) ) };
        o_v2c_check_1 <= { cam2( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), 64'b0 ) ),
                           cam2( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), 64'b0 ) ) };
        o_v2c_check_2 <= { cam2( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), 64'b0 ) ),
                           cam2( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), 64'b0 ) ) };
        o_v2c_check_3 <= { cam2( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), 64'b0 ) ),
                           cam2( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), 64'b0 ) ) };
        o_v2c_check_4 <= { cam2( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), 64'b0 ) ),
                           cam2( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), 64'b0 ) ) };
        o_v2c_check_5 <= { cam2( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), 64'b0 ) ),
                           cam2( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), 64'b0 ) ) };
        o_v2c_check_6 <= { cam2( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), 64'b0 ) ),
                           cam2( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), 64'b0 ) ) };
        o_v2c_check_7 <= { cam2( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), 64'b0 ) ),
                           cam2( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), 64'b0 ) ), 
                           cam2( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), 64'b0 ) ) };

        o_v2c_ite_0   <= { cam2( plus_sub_min( lr_last_0,                 64'b0, c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), d2l(i_di[31:28]) ) ),
                           cam2( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]),                64'b0, c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), d2l(i_di[31:28]) ) ), 
                           cam2( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]),               64'b0, c2v2l(i_c2v_0[3:0]), d2l(i_di[31:28]) ) ), 
                           cam2( plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]),               64'b0, d2l(i_di[31:28]) ) ) };
        o_v2c_ite_1   <= { cam2( plus_sub_min( lr_last_1,                 64'b0, c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), d2l(i_di[27:24]) ) ),
                           cam2( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]),                64'b0, c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), d2l(i_di[27:24]) ) ), 
                           cam2( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]),               64'b0, c2v2l(i_c2v_1[3:0]), d2l(i_di[27:24]) ) ), 
                           cam2( plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]),               64'b0, d2l(i_di[27:24]) ) ) };
        o_v2c_ite_2   <= { cam2( plus_sub_min( lr_last_2,                 64'b0, c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), d2l(i_di[23:20]) ) ),
                           cam2( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]),                64'b0, c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), d2l(i_di[23:20]) ) ), 
                           cam2( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]),               64'b0, c2v2l(i_c2v_2[3:0]), d2l(i_di[23:20]) ) ), 
                           cam2( plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]),               64'b0, d2l(i_di[23:20]) ) ) };
        o_v2c_ite_3   <= { cam2( plus_sub_min( lr_last_3,                 64'b0, c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), d2l(i_di[19:16]) ) ),
                           cam2( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]),                64'b0, c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), d2l(i_di[19:16]) ) ), 
                           cam2( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]),               64'b0, c2v2l(i_c2v_3[3:0]), d2l(i_di[19:16]) ) ), 
                           cam2( plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]),               64'b0, d2l(i_di[19:16]) ) ) };
        o_v2c_ite_4   <= { cam2( plus_sub_min( lr_last_4,                 64'b0, c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), d2l(i_di[15:12]) ) ),
                           cam2( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]),                64'b0, c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), d2l(i_di[15:12]) ) ), 
                           cam2( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]),               64'b0, c2v2l(i_c2v_4[3:0]), d2l(i_di[15:12]) ) ), 
                           cam2( plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]),               64'b0, d2l(i_di[15:12]) ) ) };
        o_v2c_ite_5   <= { cam2( plus_sub_min( lr_last_5,                 64'b0, c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), d2l(i_di[11:8] ) ) ),
                           cam2( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]),                64'b0, c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), d2l(i_di[11:8] ) ) ), 
                           cam2( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]),               64'b0, c2v2l(i_c2v_5[3:0]), d2l(i_di[11:8] ) ) ), 
                           cam2( plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]),               64'b0, d2l(i_di[11:8] ) ) ) };
        o_v2c_ite_6   <= { cam2( plus_sub_min( lr_last_6,                 64'b0, c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), d2l(i_di[7:4]  ) ) ),
                           cam2( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]),                64'b0, c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), d2l(i_di[7:4]  ) ) ), 
                           cam2( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]),               64'b0, c2v2l(i_c2v_6[3:0]), d2l(i_di[7:4]  ) ) ), 
                           cam2( plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]),               64'b0, d2l(i_di[7:4]  ) ) ) };
        o_v2c_ite_7   <= { cam2( plus_sub_min( lr_last_7,                 64'b0, c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), d2l(i_di[3:0]  ) ) ),
                           cam2( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]),                64'b0, c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), d2l(i_di[3:0]  ) ) ), 
                           cam2( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]),               64'b0, c2v2l(i_c2v_7[3:0]), d2l(i_di[3:0]  ) ) ), 
                           cam2( plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]),               64'b0, d2l(i_di[3:0]  ) ) ) };

        lr_next_0     <= plus_sub_min( lr_last_0, c2v2l(i_c2v_0[15:12]), c2v2l(i_c2v_0[11:8]), c2v2l(i_c2v_0[7:4]), c2v2l(i_c2v_0[3:0]), 64'b0 );
        lr_next_1     <= plus_sub_min( lr_last_1, c2v2l(i_c2v_1[15:12]), c2v2l(i_c2v_1[11:8]), c2v2l(i_c2v_1[7:4]), c2v2l(i_c2v_1[3:0]), 64'b0 );
        lr_next_2     <= plus_sub_min( lr_last_2, c2v2l(i_c2v_2[15:12]), c2v2l(i_c2v_2[11:8]), c2v2l(i_c2v_2[7:4]), c2v2l(i_c2v_2[3:0]), 64'b0 );
        lr_next_3     <= plus_sub_min( lr_last_3, c2v2l(i_c2v_3[15:12]), c2v2l(i_c2v_3[11:8]), c2v2l(i_c2v_3[7:4]), c2v2l(i_c2v_3[3:0]), 64'b0 );
        lr_next_4     <= plus_sub_min( lr_last_4, c2v2l(i_c2v_4[15:12]), c2v2l(i_c2v_4[11:8]), c2v2l(i_c2v_4[7:4]), c2v2l(i_c2v_4[3:0]), 64'b0 );
        lr_next_5     <= plus_sub_min( lr_last_5, c2v2l(i_c2v_5[15:12]), c2v2l(i_c2v_5[11:8]), c2v2l(i_c2v_5[7:4]), c2v2l(i_c2v_5[3:0]), 64'b0 );
        lr_next_6     <= plus_sub_min( lr_last_6, c2v2l(i_c2v_6[15:12]), c2v2l(i_c2v_6[11:8]), c2v2l(i_c2v_6[7:4]), c2v2l(i_c2v_6[3:0]), 64'b0 );
        lr_next_7     <= plus_sub_min( lr_last_7, c2v2l(i_c2v_7[15:12]), c2v2l(i_c2v_7[11:8]), c2v2l(i_c2v_7[7:4]), c2v2l(i_c2v_7[3:0]), 64'b0 );
    end
end
else begin
    o_v2c_check_0 <= 16'b0;
    o_v2c_check_1 <= 16'b0;
    o_v2c_check_2 <= 16'b0;
    o_v2c_check_3 <= 16'b0;
    o_v2c_check_4 <= 16'b0;
    o_v2c_check_5 <= 16'b0;
    o_v2c_check_6 <= 16'b0;
    o_v2c_check_7 <= 16'b0;

    o_v2c_ite_0   <= 16'b0;
    o_v2c_ite_1   <= 16'b0;
    o_v2c_ite_2   <= 16'b0;
    o_v2c_ite_3   <= 16'b0;
    o_v2c_ite_4   <= 16'b0;
    o_v2c_ite_5   <= 16'b0;
    o_v2c_ite_6   <= 16'b0;
    o_v2c_ite_7   <= 16'b0;

    lr_next_0     <= 64'b0;
    lr_next_1     <= 64'b0;
    lr_next_2     <= 64'b0;
    lr_next_3     <= 64'b0;
    lr_next_4     <= 64'b0;
    lr_next_5     <= 64'b0;
    lr_next_6     <= 64'b0;
    lr_next_7     <= 64'b0;
end

endmodule
